package com.zys.config;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class FileThreadConfig {

    private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();

    @Bean
    public ThreadPoolTaskExecutor fileThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(CORE_POOL_SIZE==0?4:CORE_POOL_SIZE);
        executor.setMaxPoolSize(executor.getCorePoolSize() * 2);
        executor.setQueueCapacity(100);
        executor.setKeepAliveSeconds(60);
        executor.setThreadNamePrefix("file-thread-");
        executor.initialize();
        return executor;
    }
}
